package common.mq.basic.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import common.mq.po.Message;

public class QueueUtil {
	
	public static String getFruthestMessage(Map<String,Message> areaMap){
		Set<String> keys = areaMap.keySet();
		String fruthestM = null ;
		int fruthestTime = Integer.MAX_VALUE;
		for(String key : keys){
			Message m = areaMap.get(key);
			if(fruthestTime >= m.getReceiveTime()){
				fruthestM = key;
			}
		}
		return fruthestM;
	}
	
	public static List<Message> getMessagesByCategory(Map<String,Message> areaMap , String category){
		List<Message> mList = new ArrayList<Message>();
		Set<String> keys = areaMap.keySet();
		for(String key : keys){
			Message m = areaMap.get(key);
			if(m.getCategory().equals(category)){
				mList.add(m);
			}
		}
		return mList;
	}
}
